<template>
  <el-dialog
    title="收支明细"
    :visible.sync="visible"
    width="70%"
    append-to-body
  >
    <avue-crud
      ref="detailCrud"
      v-model="form"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="detailTableOption"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
    ></avue-crud>
  </el-dialog>
</template>

<script>
import { detailTableOption } from '@/const/crud/points/canned';
import { fetchDetailList } from '@/api/core/canned';
import crudMixins from '@/mixins/crud';

export default {
  name: 'Detail',
  mixins: [crudMixins],
  props: {
    id: {
      type: [Object, String],
    },
    value: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      form: {},
      detailTableOption: detailTableOption(),
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
  },
  watch: {
    visible(val) {
      if (val) {
        this.$nextTick(() => {
          this.$refs.detailCrud.searchReset()
          this.id && this.getList();
        });
      } else {

      }
    },
  },
  methods: {
    // 列表查询
    getList(page, refresh) {
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      if (this.searchForm.createTime && this.searchForm.createTime.length) {
        this.searchForm.startDate = this.searchForm.createTime[0];
        this.searchForm.endDate = this.searchForm.createTime[1];
        delete this.searchForm.createTime
      }
      this.tableLoading = true;
      fetchDetailList(
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
            canId:this.id,
          },
          this.searchForm
        )
      )
        .then((response) => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },

  },
};
</script>

<style lang="scss" scoped></style>
